# 设置目标文件夹路径
$targetFolder = "F:\BaiduSyncdisk\DailyUseGreen\1-567"

# 要保留的文件夹名称
$foldersToKeep = @("CT", "MR")

# 获取 A 文件夹下的所有一级子文件夹
$firstLevelFolders = Get-ChildItem -Path $targetFolder -Directory

foreach ($firstFolder in $firstLevelFolders) {
    # 获取该一级子文件夹下的所有二级子文件夹
    $secondLevelFolders = Get-ChildItem -Path $firstFolder.FullName -Directory

    foreach ($secondFolder in $secondLevelFolders) {
        # 检查二级文件夹名称是否在保留列表中
        if ($foldersToKeep -notcontains $secondFolder.Name) {
            # 提示用户确认删除
            $confirmation = Read-Host "确认要删除文件夹: $($secondFolder.FullName) ? (Y/N)"
            if ($confirmation -eq "") {
                # 删除文件夹
                Remove-Item -Path $secondFolder.FullName -Recurse -Force
                Write-Host "已删除文件夹: $($secondFolder.FullName)"
            } else {
                Write-Host "跳过删除文件夹: $($secondFolder.FullName)"
            }
        }
    }
}

